package com.punai.customer.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punai.common.utils.SecurityUtils;
import com.punai.customer.domain.CusFeature;
import com.punai.customer.domain.bo.CusLinkFeatureBo;
import com.punai.customer.domain.contants.CusConstants;
import com.punai.customer.domain.vo.CusLinkFeatureVo;
import com.punai.customer.mapper.CusFeatureMapper;
import com.punai.customer.mapper.CusGxChapterMapper;
import com.punai.customer.service.ICusFeatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 特征Service业务层处理
 *
 * @author ruoyi
 * @date 2022-12-04
 */
@Service
public class CusFeatureServiceImpl extends ServiceImpl<CusFeatureMapper,CusFeature> implements ICusFeatureService
{
    @Autowired
    private CusFeatureMapper cusFeatureMapper;
    @Autowired
    private CusGxChapterMapper cusGxChapterMapper;

    @Override
    public List<CusFeature> getByNameSearch(CusFeature cusFeature) {
        return cusFeatureMapper.selectIdFeatureNameList(cusFeature);
    }

    @Override
    public CusLinkFeatureBo getChildById(String id) {
        CusLinkFeatureBo cusLinkFeatureBo = cusFeatureMapper.selectCusFeatureById(id, SecurityUtils.getCompanyId());
        cusLinkFeatureBo.setItemNames(CollUtil.toList(cusLinkFeatureBo.getFeatureValues().split("\\|")));
        return cusLinkFeatureBo;
    }

    @Override
    public List<CusFeature> getFeatureListByChapterId(CusLinkFeatureVo cusLinkFeatureVo) {
        Long companyId = SecurityUtils.getCompanyId();
        String featureAliasName = cusGxChapterMapper.getFeatureListById(cusLinkFeatureVo.getChapterId(), companyId, CusConstants.FEATURE_ALIAS_NAME_SPLIT_FLAG);
//        List<AssetFeature> result = assetFeatureMapper.selectAssetFeatureListByAliasName(featureAliasName,itemId,versionsId,noInIds,FeeitemConstants.GX_TYPE);
        List<CusFeature> result = cusFeatureMapper.selectListByAliasNameNew(companyId,featureAliasName,cusLinkFeatureVo.getOnIds());
        return result;
    }
}
